package com.jonas.test.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.jonas.test.dao.TestDao;

/**
 * Created by yzYang on 2015/1/26.
 */
@Controller

public class indexController {

    @Autowired
    TestDao testDao;

    @RequestMapping("/index")
    public ModelAndView indexPage(Model model){
        ModelAndView mv = new ModelAndView("index");
        mv.addObject("message", "hello world!");

        return mv;
    }

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public ModelAndView login()
    {
        return new ModelAndView("login");
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ModelAndView dologin(@RequestParam("username") String uname,
                                @RequestParam("passwd") String passwd){
        System.out.println(uname);
        System.out.println(passwd);
        ModelAndView mv = new ModelAndView("loginSuccess");
        mv.addObject("uname", uname);
        mv.addObject("passwd", passwd);
        testDao.userList();

        return mv;
    }

}
